/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 版本: 苏州公安统一用户管理平台1.0
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名:IndexController.java
 * <p>
 * 类产生时间: 2012-6-10 下午9:07:35
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 所在组 : 苏州公安统一用户管理平台
 * <p>
 * 所在部门: 电信/国土——技术二部
 * <p>
 * <p>
 */
package com.oceansoft.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.oceansoft.common.util.encrypt.Blowfish;
import com.oceansoft.core.common.constant.Constant;
import com.oceansoft.core.common.util.CommonUtilCache;
import com.oceansoft.core.controller.util.ApiResult;
import com.oceansoft.core.dao.util.SQLUtil;
import com.oceansoft.core.domain.Message;
import com.oceansoft.core.domain.SysDept;
import com.oceansoft.core.domain.SysResource;
import com.oceansoft.core.domain.SysUser;
import com.oceansoft.core.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 个人登录首页
 * 
 * @author chenw
 * 
 */
@Controller
@RequestMapping("/vue")
public class VueProfileController {
	private static final Logger logger = Logger.getLogger(VueProfileController.class.getName());
	@Resource
	private ISysUserService userService;
	@Resource
	private ISysDeptService sysDeptService;
	@Resource
	private ISysResourceService sysResourceService;
	@Resource
	private IUUMSRoleService roleService;
	@Resource
	private  ISysSsoLogService  ssoLogService;

	@RequestMapping("/auth/{policeNum}/{password}")
	public ApiResult login(HttpServletRequest request,@PathVariable("policeNum") String policeNum,@PathVariable("password") String password) {
//		password = request.getAttribute("password").toString();
		ApiResult apiResult = new ApiResult();
			if (null != policeNum && StringUtils.hasText(policeNum)) {
				SysUser user = userService.findUserByPoliceNum(policeNum);
				if (user == null) {
					return apiResult.failure("该用户不存在！");
				} else {
					if (!password.equals(
							new Blowfish(Constant.ENCRYPT_SALT).decryptString(user.getPassword()))) {
						return apiResult.failure("用户名或密码错误！");
					} else {
						// 屏蔽个人信息
						user.setPassword(null);
						return apiResult.success(200,"",user);
					}
				}
			} else {
				return apiResult.failure("登录输入信息有误！");
			}
	}

	@RequestMapping("/getMenu/{policeNum}")
	public ApiResult getMenu(HttpServletRequest request,@PathVariable("policeNum") String policeNum) {
		ApiResult apiResult = new ApiResult();
		// 加载当前用户资源列表
		Map<String, ArrayList<SysResource>> map = sysResourceService.findUserResources(policeNum);
		return apiResult.success(map);
	}
}
